<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <title>找回密码</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f2f2f2;
        }
        .container {
            width: 400px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            background-color: #fff;
        }
        .container h2 {
            text-align: center;
            margin-bottom: 20px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
        }
        .form-group input[type="email"] {
            width: 100%;
            padding: 8px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
        }
        .form-group input[type="submit"] {
            width: 100%;
            padding: 10px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .form-group input[type="submit"]:hover {
            background-color: #45a049;
        }
        .link {
            text-align: center;
            margin-top: 20px;
        }
        .link a {
            color: #0066cc;
            text-decoration: none;
        }
        .link a:hover {
            text-decoration: underline;
        }
        .error {
            color: red;
            margin-top: -10px;
            margin-bottom: 10px;
            font-size: 14px;
        }
        .success {
            color: green;
            margin-top: -10px;
            margin-bottom: 10px;
            font-size: 14px;
        }
    </style>
    <script>
        function submitForm(event) {
            event.preventDefault();
            var email = document.getElementById('email').value;
            var errorContainer = document.getElementById('error-container');
            var successContainer = document.getElementById('success-container');

            var xhr = new XMLHttpRequest();
            xhr.open("POST", "ForgotPasswordServlet", true);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    var response = JSON.parse(xhr.responseText);
                    if (response.status === "error") {
                        errorContainer.textContent = response.message;
                        successContainer.textContent = "";
                    } else if (response.status === "success") {
                        successContainer.textContent = response.message;
                        errorContainer.textContent = "";
                    }
                }
            };
            xhr.send("email=" + encodeURIComponent(email));
        }
    </script>
</head>
<body>
    <div class="container">
        <h2>找回密码</h2>
        <form onsubmit="submitForm(event)">
            <div class="form-group">
                <label for="email">邮箱：</label>
                <input type="email" id="email" name="email" required />
            </div>
            <div class="form-group">
                <input type="submit" value="提交请求" />
            </div>
        </form>
        <div class="error" id="error-container"></div>
        <div class="success" id="success-container"></div>
        <div class="link">
            <a href="login.jsp">返回登录</a>
        </div>
    </div>
</body>
</html>
